package com.antler.smt.portal.service.impl;

import com.antler.smt.entity.JobOrderEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.mapper.JobOrderEntityMapper;
import com.antler.smt.portal.mapper.JobOrderInfoMapper;
import com.antler.smt.request.portal.JobOrderReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.JobOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 招聘订单实现
 *
 * @author zhangyi
 * @date 2018/9/20 16:56
 */
@Service
public class JobOrderServiceImpl implements JobOrderService {

    @Autowired
    private JobOrderEntityMapper jobOrderEntityMapper;
    @Autowired
    private JobOrderInfoMapper jobOrderInfoMapper;

    /**
     * 获取订单详细信息
     *
     * @param orderId
     * @return
     */
    @Override
    public Result detailedOrder(Long orderId) {
        JobOrderEntity jobOrderEntity =
                jobOrderEntityMapper.selectByPrimaryKey(orderId);
        return new Result(jobOrderEntity);
    }


    /**
     * 批量删除订单（设置删除标志位）
     *
     * @param orderIds
     * @return
     */
    @Override
    public Result batchDeleteOrder(List<Integer> orderIds) {
        int i = jobOrderInfoMapper.batchDeleteOrder(orderIds);
        return new Result(i);
    }

    /**
     * 彻底删除订单 修改二次设置订单标志位
     *
     * @param orderId
     * @return
     */
    @Override
    public Result deleteThoroughOrder(List<Integer> orderId) {
        int i = jobOrderInfoMapper.deleteThoroughOrder(orderId);
        return new Result(i);
    }

    /**
     * 获取有效订单列表
     *
     * @param orderStatus
     * @param memberId
     * @return
     */
    @Override
    public Result jobOrderList(List<Integer> orderStatus, Long memberId) {
        Result result = null;
        //过滤未删除的有效订单 invalid_status  1：初次删除 2：彻底删除
        JobOrderReq jobOrderReq = new JobOrderReq();
        jobOrderReq.setMemberId(memberId);
        jobOrderReq.setOrderStatus(orderStatus);
        Page<JobOrderEntity> jobOrderEntities = jobOrderInfoMapper.jobOrderList(jobOrderReq);
        if(jobOrderEntities != null){
            result = new Result(new PageInfo(jobOrderEntities));
        }else{
            result = new Result(ResultCodeEnum.QUERY_DATA_ERROR,"查询订单列表失败！");
        }
        return result;
    }

    /**
     * 查看当前用户的回收站列表
     *
     * @param memberId
     * @return
     */
    @Override
    public Result recycleBinOrderLists(Long memberId) {
        Result result = null;
        Page<JobOrderEntity> jobOrderEntities = jobOrderInfoMapper.recycleBinOrderLists(memberId);
        if(jobOrderEntities != null){
            result = new Result(new PageInfo(jobOrderEntities));
        }else{
            result = new Result(ResultCodeEnum.QUERY_DATA_ERROR,"查询回收站的订单列表");
        }
        return result;
    }
}
